package com.losl.common.core.domain;
import java.util.HashMap;

/**
 * 返回的ajax对象
 * @author Maxwell
 */
public class Result extends HashMap<String,Object> {
    private static final String CODE="code";
    private static final String MSG="msg";
    private static final String DATA="data";

    public Result(){
    }

    public Result(int code, String msg){
        super.put(CODE,code);
        super.put(MSG,msg);
    }

    public Result(int code, String msg, Object object){
        super.put(CODE,code);
        super.put(MSG,msg);
        if (object!=null){
            super.put(DATA,object);
        }
    }

    public static Result success(){
        return success("操作成功");
    }

    public static Result success(String msg){
        return success(msg,null);
    }

    public static Result success(Object data){
        return success("操作成功",data);
    }

    public static Result success(String msg, Object data){
        return success(200,msg,data);
    }

    /**
     *
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static Result success(int code, String msg, Object data){
        return new Result(code,msg,data);
    }

    public static Result error(){
        return error("操作失败");
    }

    public static Result error(String msg){
        return error(msg,null);
    }

    public static Result error(Object data){
        return error("操作失败",data);
    }

    public static Result error(int code, Object data){
        return new Result(code,"操作失败",data);
    }

    public static Result error(String msg, Object data){
        return new Result(400,msg,data);
    }

    @Override
    public Result put(String key, Object obj){
        super.put(key,obj);
        return this;
    }
}
